/**
 * \file menu.c
 * \brief  Jeu 2D: REVENGE.
 * \author Groupe Mobius 1A4  
 * Les Membres : -Ala YAHMADI
 *               -Anis SAHNOUN
 *               -Chourouk BOUKHRIS
 *               -Ghassen FERCHICHI  
 *               -Houssem CHIBANI
 *               -Med.Hedi FRIHA
 * \version 0.1
 * \date  23 Mai 2013
 *
 * PROJET C
 *
 */

#include <allegro.h>

int main() 
{

BITMAP* img[5];  /**  *@brief Notre tableau de type BITMAP qui contient tous les images de notre menu */
BITMAP*  Buffer ;
 
int menu=0; /**  *@brief On a déclaré une variable de type int initialisé à (-1) */
int inmenu=1;  /**  *@brief On a déclaré une variable de type int initialisé à (1) */
int c=0;
/* General initialization function */
allegro_init();
if (install_keyboard() == -1) {
allegro_message("Error! %s", allegro_error);
return -1;
}
set_color_depth(24);
if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, 1020, 600, 0, 0) != 0) {
set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); /* here’s the command for text mode */
allegro_message("Unable to initialize video mode!\n%s\n", allegro_error);
return 1;
}


Buffer = create_bitmap(1020, 600);

img[0]= load_bitmap("../Images/Menu.bmp", NULL);  /**  *@brief Chargement de la 1 ere image */
img[1]= load_bitmap("../Images/Menu1.bmp", NULL); /**  *@brief Chargement de la 2 eme image */
img[2]= load_bitmap("../Images/Menu2.bmp", NULL); /**  *@brief Chargement de la 3 eme image */
img[3]= load_bitmap("../Images/Menu3.bmp", NULL); /**  *@brief Chargement de la 4 ere image */
img[4]= load_bitmap("../Images/Menu4.bmp", NULL); /**  *@brief Chargement de la 4 ere image */


	while (!key[KEY_ESC]) {

	clear_bitmap(Buffer);

	if (  key[KEY_DOWN] && (inmenu==1) )	 /**  *@brief la boucle du menu a chaque fois la variable menu  de type int change   */
	{menu++;}
		if (menu==0) /**  *@brief a chaque fois on affiche l'image son indice correspond à l'image qu'on va la charger    */
		{	
	
	blit(img[0], Buffer, 0, 0, 0, 0, img[0]->w, img[0]->h);	
	blit(Buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
	}
	else if (menu==2)
	{

	blit(img[2], Buffer, 0, 0, 0, 0, img[2]->w, img[2]->h);	
	blit(Buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
	}
	else if (menu==1)
	{	
	blit(img[1], Buffer, 0, 0, 0, 0, img[1]->w, img[1]->h);	
	blit(Buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);	
	}
	else if (menu==3)
	{	
	blit(img[3], Buffer, 0, 0, 0, 0, img[3]->w, img[3]->h);	
	blit(Buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);	
	menu=(-1);

	}
	if (  key[KEY_ENTER] && menu==0)

{inmenu=0;
c=1;
while(c==1)
{
clear(Buffer);
blit(img[4], Buffer, 0, 0, 0, 0, img[4]->w, img[4]->h);	
	blit(Buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
	
}
}
	
clear_keybuf();
readkey();

}	

	destroy_bitmap(img[0]); //Release the bitmap data
	destroy_bitmap(img[1]); //Release the bitmap data
	destroy_bitmap(img[2]); //Release the bitmap data 
	destroy_bitmap(Buffer);
	

		

return 0;	
	
}





